#pragma once

#include "memory.h"
#include "csdk.h"
#include <d3d9.h>
#include <d3dx9.h>
#pragma comment(lib,"d3d9.lib")
#pragma comment(lib,"d3dx9.lib")


namespace render {
	class overlay {
		struct wnd_rec :public RECT{
			int width() { return right - left ; }
			int height() { return  bottom - top ; }

		};
	public:
		overlay(std::string_view window_name,std::string_view class_name);

		overlay(HWND hWnd);

		~overlay();

		void create_overlay(std::string_view window_name, std::string_view class_name, HWND targethwnd);

		LPDIRECT3DDEVICE9 m_device = nullptr;
	private:
		static LRESULT CALLBACK m_win_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
		wnd_rec target_rect;
		wnd_rec overlay_rect;

		void init_dx9();
		LPDIRECT3D9 m_d3d = nullptr;

		bool m_initialized = false;
	};
	class dx_renderer {
	public:
		dx_renderer(IDirect3DDevice9* m_device);
		~dx_renderer();
		void begain_renderer();
		void end_renderer();
		void draw_rect(int x0,int y0,int weight,int height,unsigned long color);
		void draw_line(int x0, int y0, int x1, int y1, unsigned long color);
		void draw_text(std::string_view text, int x, int y, unsigned long color);
	private:
		IDirect3DDevice9* d3d_device;
		ID3DXFont* m_font = nullptr;
		ID3DXLine* m_line = nullptr;
	};

}
